02. Numbers

You can also perform calc

Numbers

Defining a number in JavaScript is actually pretty simple. The Number data type includes any positive or negative integer, as well as decimals. Entering a number into the console will return it right back to you.

3 

Returns: 3

There, you did it.

Arithmetic operations

You can also perform calculations with numbers pretty easily. Basically type out an expression the way you would type it in a calculator.

3 + 2.1

Returns: 5.1

Now you try!

Matching Expressions

QUIZ QUESTION::

Enter the expressions (one at a time) into the console and determine what each expression evaluates to.

ANSWER CHOICES:



Expression

Solution

-4

4

92

12

-92

-12

SOLUTION:

Expression

Solution

-4

4

-92

-12

What about comparing Numbers

Comparing numbers

What about comparing numbers? Can you do that? Well of course you can!

Just like in mathematics, you can compare two numbers to see if one’s greater than, less than, or equal to the other.

5 > 10

Returns: false

5 < 10

Returns: true

5 == 10

Returns: false

Comparisons between numbers will either evaluate to true or false. Here are some more examples, so you can try it out!

Operator Meaning
< Less than
> Greater than
<= Less than or Equal to
>= Greater than or Equal to
== Equal to
!= Not Equal to

Comparison Practice

QUIZ QUESTION::

Enter the expressions (one at a time) into the console and determine what each expression evaluates to.

ANSWER CHOICES:



Expression

Solution

false

false

true

true

SOLUTION:

Expression

Solution

false

false

false

false

true

true

true

true

callout

TIP: The values true and false have significant importance in JavaScript. These values are called Booleans and are another data type in JavaScript. Later in this lesson, you’ll learn more about why Booleans are so important in programming.